package org.net.cms.mapper;

import org.apache.ibatis.annotations.*;
import org.net.cms.controller.admin.notice.vo.NoticeReqVO;
import org.net.cms.dao.NoticeDto;

import java.util.List;

@Mapper
public interface NoticeMapper {

    @Select("select * from notice where deleted = 0")
    List<NoticeDto> listAllNotice();

    @Select("select * from notice where status = #{type} and deleted = 0")
    List<NoticeDto> listPublishNotice(int type);

    @Select("select * from notice where id = #{id} and deleted = 0")
    NoticeDto getNoticeById(int id);

    @Insert("INSERT INTO notice (title, content, status, date) " +
            "VALUES (#{title}, #{content}, #{status}, #{date})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int addNotice(NoticeReqVO notice);

    @Update("UPDATE notice SET title = #{title}, content = #{content}, status = #{status}, date = #{date} " +
            "WHERE id = #{id} and deleted = 0")
    int updateById(NoticeReqVO notice);

    @Update("UPDATE notice SET deleted = 1 WHERE id = #{id} and deleted = 0")
    int deleteById(Integer id);
}
